﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sern.Common;
using Sern.Common.Fakes;

namespace Sern.Test
{    
    public class RepositoryFactory
    {
        public static IRepository<T> CreateStub<T>()
        {
            List<T> entities = new List<T>();

            return new StubIRepository<T>()
                {
                    AddManyIEnumerableOfT0 = newRows => entities.AddRange(newRows),
                    AddT0 = newRow => entities.Add(newRow),
                    DeleteManyIEnumerableOfT0 = rows => rows.ToList().ForEach(row => entities.Remove(row)),
                    DeleteT0 = row => entities.Remove(row),
                    RecordsGet = () => entities.AsQueryable(),
                    Save = () => { },
                    UpdateManyIEnumerableOfT0 = rows => { },
                    UpdateT0 = row => { }
                };
        }
    }
}
